*  FILE NAME: INVADJUS.PRG
*  BY: NURJADI PURNAMA
*  DATE: January 25, 1993
*  DESC:
*  CALLED BY:
*  DATA FILES:

*set proc to sospro
SET PROC TO BOXPROC
set proc to ADDREPRO
do start

dr1='N:'
DR='N:'
F1='PATIENT'
F2='REVENUE'

SELE 1
SET EXCLU OFF
USE &DR1&F1 INDE &DR1&F1
SELE 2
SET EXCLU OFF
USE &DR&F2
PL1=0
DO WHILE .T.
   SET COLO TO BG+/B
   CLEAR
   *  DO HDCOMP
   DO ADDRESSV
   DO ADDRCHAN
   SET COLO TO BG+/B,W+/N
   STORE SPACE(16) TO PAYON,PAYNBER
   PL1=1
   DO BOX2 WITH 11,3,"CHANGE PAYMENT MODE TO :","CASH","CREDIT",'GR+','RB','GR+','R',PL1,.F.,.T.
   IF LAST()=27
      SET COLO TO
      CLEAR
      RETURN
   ENDIF
   DO CASE
   CASE PL1=1
      KTR='CHANGE PAYMENT MODE TO CASH PAYMENT'
   CASE PL1=2
      KTR='CHANGE PAYMENT MODE TO CREDIT PAYMENT'
   CASE PL1=3
      RETURN
   ENDCASE
   SET COLO TO GR+/B,W+/N
   *   @ 8,40-LEN(KTR)/2 SAY KTR
   @ 8,3 SAY KTR
   SET COLO TO BG+/B,W+/N
   @  9, 3 CLEAR TO 19,68
   NOFT=SPACE(5)
   @ 12,3 SAY 'INVOICE NO.  : 'GET  NOFT
   READ

   SELE 2
   SET EXCLU OFF
   USE &DR&F2
   LOCATE FOR INV_NBER=NOFT
   IF .NOT. FOUND()
      LOOP
   ENDIF
   PATCOD=PAT_FILCOD
   PAYMOD1=PAY_MODE
   IF ALLTRIM(INV_STAT)='V' .OR. ALLTRIM(INV_STAT)='CR'
      SET COLO TO BG+/B*
      SET CURSOR OFF
      @ 18,18 say '>>>>> THE INVOICE NUMBER IS ALREADY VOID <<<<<'
      WAIT ''
      SET CURSOR ON
      SET COLO TO BG+/B
      @ 15,0 CLEAR
      RETURN
   ENDIF
   IF PL1=2
      IF PAYMOD1='CREDIT'
         SET COLO TO BG+*/B,W+/N
         @ 12,30 SAY 'THIS INVOICE HAS THE CREDIT PAYMENT'
         WAIT''
         SET COLO TO BG+/B,W+/N
         LOOP
      ENDIF
   ENDIF
   IF HEALTHLINE
      KET='HEALTHLINE'
   ELSE
      KET=SPACE(10)
   ENDIF
   SET COLO TO BG+/B,W+/N
   @ 8,40 SAY KET
   @ 10,3 SAY 'PATIENT CODE : '+PATCOD
   @ 10,40 SAY 'PATIENT NAME    : '+ ALLTRIM(PAT_NAME)+' '+ALLTRIM(PAT_F_NAME)
   @ 12,40 SAY 'DATE OF INVOICE : '+DTOC(DATE_VISIT)
   IF PAY_MODE='CARD'
      @ 14,3 SAY 'PAYMENT MODE : '+ALLTRIM(PAY_MODE)+' '+ALLTRIM(PAY_ON)
      @ 14,40 SAY 'CARD NUMBER     : '+PAY_NBER
   ELSE
      @ 14,3 SAY 'PAYMENT MODE : '+ALLTRIM(PAY_MODE)
   ENDIF
   IF AEADECI
      @ 16,40 SAY 'INVOICE AMOUNT  : '+TRANS(TOTAL_FEE,'###,###.##')
      @ 16,3 SAY 'CASH PAYMENT : '+TRANS(TOTAL_CASH,'###,###.##')
      @ 18,40 SAY 'CREDIT VOUCHER  : '+TRANS(TOTAL_CRED,'###,###.##')
      IF AEAHEAL
         @ 18,3 SAY 'HEALTHLINE   : '+TRANS(TOTAL_HL,'###,###.##')
      ENDIF
   ELSE
      @ 16,40 SAY 'INVOICE AMOUNT  : '+TRANS(TOTAL_FEE,'##,###,###')
      @ 16,3 SAY 'CASH PAYMENT : '+TRANS(TOTAL_CASH,'##,###,###')
      @ 18,40 SAY 'CREDIT VOUCHER  : '+TRANS(TOTAL_CRED,'##,###,###')
      IF AEAHEAL
         @ 18,3 SAY 'HEALTHLINE   : '+TRANS(TOTAL_HL,'##,###,###')
      ENDIF
   ENDIF

   SET COLO TO GR+/B,W+/N
*   @ 18,40 SAY KET
   SET COLO TO BG+/B,W+/N
   TCAS=TOTAL_CASH
   TCRE=TOTAL_CRED
   OTCUR=OTHE_CURR
   OTAMT=OTHE_AMNT
   OTRAT=RATE_CURR
   PIL1=1
   DO BOX2 WITH 21,0,"DO YOU WANT TO :","CONFIRM","CANCEL",'GR+','RB','GR+','R',PIL1,.F.,.T.
   IF PIL1=2 .OR. LASTKEY()=27
      CLOSE ALL
      LOOP
   ENDIF
   DO CASE
   CASE PL1=1
      CHNG=.T.
      PL15=1
      DO BOX3 WITH 21,38,'MODE OF PAYMENT :',"CASH","CARD","CHEQUE",'W+','G','W+','N',PL15,.F.,.T.
      DO CASE
      CASE PL15=1
         PAYMODE='CASH'
      CASE PL15=2
         PAYMODE='CARD'
         SET COLOR TO BG+/B
         @ 21,0 CLEA
         @ 23,0  SAY 'PAYMENT BY CARD ISSUED BY :'
         svcash=savescreen(0,0,24,79)
         spes    = 'Y'
         DO WHILE spes='Y'
            SELE 8
            F8='CARDTBL'
            SET EXCLU OFF
            USE &DR&F8
            GO TOP
            CNT=0
            count to cnt
            CNT=CNT+1
            GO TOP
            if cnt>0
               set colo to bg+/gr+,w+/n
               DECLARE FILD[CNT]
               DECLARE aCardnam[CNT]
               DECLARE aCardcod[CNT]
               STOR 0 TO CR

               DO WHILE .NOT. EOF()
                  set colo to bg+/gr+,w+/n
                  cr=cr+1
                  fild[cr]=CARD_NAME
                  aCardnam[cr]=CARD_NAME
                  aCardcod[cr]=ACCT_CODE
                  skip
               ENDD
               CR=CR+1
               fild[cr]='OTHER'
               aCardnam[cr]='OTHER'
               aCardcod[cr]='1020609'
               SET COLO TO BG+/GR+,W+/N
               inkey()
               @ 17,27 CLEAR TO 24,52
               @ 17,27 TO 24,52 DOUBLE
               cari=achoice(18,29,23,51,FILD)
               mix=lastkey()
               DO CASE
               CASE MIX=13
                  IF aCardcod[cari] = '1020609'
                     SPES = 'N'
                  ELSE
                     SPES    = 'Y'
                  ENDI
                  PAYON   = aCardnam[cari]
                  LYYR=SAVESCREEN(0,0,24,79)
                  SET COLOR TO BG+/B,W/N
                  restscreen(0,0,24,79,svcash)
                  if spes='Y'
                     @ 23,28 say PAYON
                     DO BOXE WITH 22,46,'CARD NUMBER :','PAYNBER','W+','G','W+','N',16,.F.,.F.
                  ELSE
                     DO BOXE WITH 22,0,'PAYMENT BY CARD ISSUED BY :','PAYON','W+','G','W+','N',16,.F.,.F.
                     DO BOXE WITH 22,46,'CARD NUMBER :','PAYNBER','W+','G','W+','N',16,.F.,.F.
                  endif
                  PLX=1
                  DO BOX2 WITH 20,20,'DO YOU WANT TO :','CONFIRM','CANCEL','W+','B','GR+','N',PLX,.T.,.T.
                  IF PLX=1
                     EXIT
                  ELSE
                     RESTSCREEN(0,0,24,79,LYYR)
                     SPES='Y'
                     LOOP
                  ENDIF
               CASE LASTKEY()=27
                  SPES='Y'
               ENDC
            ELSE
               EXIT
            ENDIF
         ENDDO

      CASE PL15=3
         PAYMODE='CHEQUE'
      OTHER
         LOOP
      ENDCASE
      SELE 2
      SET EXCLU OFF
      USE &DR&F2
      LOCAT FOR INV_NBER=NOFT
      IF .NOT. FOUND()
         LOOP
      ENDIF
      IF REC_LOCK()
         REPL PAY_MODE WITH PAYMODE
         REPL PAY_ON WITH PAYON
         REPL PAY_NBER WITH PAYNBER
         IF TOTAL_CASH=0
            REPL TOTAL_CASH WITH TCRE, TOTAL_CRED WITH 0
         ENDIF
      ENDIF
      UNLOCK
   CASE PL1=2
      CHNG=.T.
      SELE 2
      SET EXCLU OFF
      USE &DR&F2
      LOCAT FOR INV_NBER=NOFT
      IF .NOT. FOUND()
         LOOP
      ENDIF
      IF REC_LOCK()
         REPL TOTAL_CASH WITH 0, TOTAL_CRED WITH TCAS
         REPL PAY_MODE WITH 'CREDIT'
      ENDIF
      UNLOCK
   ENDCASE
ENDDO

*Formatted by: Herman T Ver. 7.1  on March 29, 1996.
